package src.exercise;

import java.io.File;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.stage.FileChooser;
import javafx.stage.Stage;

public class DemoFileChooser extends Application{

	private Scene scene;
	@Override
	public void start(Stage primaryStage) throws Exception {
		
		Scene scene = new Scene(cteateUi());
		
		this.scene = scene;
		primaryStage.setTitle("FileChooser");
		primaryStage.setScene(scene);
		primaryStage.show();
	}

	private Parent cteateUi() {
		HBox  hbox = new HBox();
		hbox.setSpacing(10);
		hbox.setPadding(new Insets(10));
		
		Label path = new Label("PATH");
		TextField tf = new TextField();
		Button button = new Button("...");
		
		hbox.getChildren().addAll(path,tf,button);
		
		button.setOnAction(new EventHandler<ActionEvent>() {
			
			@Override
			public void handle(ActionEvent event) {
				FileChooser chooser = new FileChooser();
				File selested  =chooser.showOpenDialog(DemoFileChooser.this.scene.getWindow());
				System.out.println(selested);
				
				tf.setText(selested.getAbsolutePath());
			}
		});
		return hbox;
	}
	public static void main(String[] args) {
		Application.launch(args);
	}
}
